home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoTabBar.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  7.9 KB  |  276 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 2003 Ariya Hidayat <ariya@kde.org>
  3.    Copyright (C) 2003 Norbert Andres <nandres@web.de>
  4.    Copyright (C) 2002 Laurent Montel <montel@kde.org>
  5.    Copyright (C) 1999 David Faure <faure@kde.org>
  6.    Copyright (C) 1999 Boris Wedl <boris.wedl@kfunigraz.ac.at>
  7.    Copyright (C) 1998-2000 Torben Weis <weis@kde.org>
  8.  
  9.    This library is free software; you can redistribute it and/or
  10.    modify it under the terms of the GNU Library General Public
  11.    License as published by the Free Software Foundation; either
  12.    version 2 of the License, or (at your option) any later version.
  13.  
  14.    This library is distributed in the hope that it will be useful,
  15.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.    Library General Public License for more details.
  18.  
  19.    You should have received a copy of the GNU Library General Public License
  20.    along with this library; see the file COPYING.LIB.  If not, write to
  21.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22.  * Boston, MA 02110-1301, USA.
  23. */
  24.  
  25. #ifndef kotabbar_h
  26. #define kotabbar_h
  27.  
  28. #include <qwidget.h>
  29. #include <qstringlist.h>
  30. #include <koffice_export.h>
  31. class KoTabBarPrivate;
  32.  
  33. /**
  34.  * The KoTabBar class provides a tab bar, for use to switch active
  35.  * page/sheet in a document.
  36.  *
  37.  * The tab bar is typically used in the main view. 
  38.  * It is the small widget on the bottom left corner. 
  39.  * Pages/sheets are displayed as tabs, clicking on
  40.  * one of the tab will activate the corresponding sheet (this is actually
  41.  * done in main view). Current active page/sheet is marked by bold text.
  42.  *
  43.  * The tab bar supports page/sheet reorder by dragging a certain tab
  44.  * and move it to another location. The main view should handle the necessary
  45.  * action to perform the actual reorder.
  46.  *
  47.  * There are four scroll buttons available in the tab bar. They are used
  48.  * to shift the tabs in left and right direction, for example when there
  49.  * are more tabs than the space available to display all tabs.
  50.  *
  51.  * Since a page/sheet can be hidden, the tab bar only shows the visible page/sheet.
  52.  * When a hidden page or sheet is shown again, it will be on the same position as
  53.  * before it was hidden.
  54.  *
  55.  * When the document is protected, it is necessary to set the tab bar as
  56.  * read-only using setReadOnly (see also readOnly). If it is set to true,
  57.  * tabs can not be moved by dragging and context menu will not be displayed.
  58.  *
  59.  * @short A bar with tabs and scroll buttons.
  60.  */
  61. class KOFFICEUI_EXPORT KoTabBar : public QWidget
  62. {
  63.     Q_OBJECT
  64.     
  65.     Q_PROPERTY( QString activeTab READ activeTab WRITE setActiveTab )
  66.     Q_PROPERTY( bool readOnly READ readOnly WRITE setReadOnly )
  67.     Q_PROPERTY( QStringList tabs READ tabs WRITE setTabs )
  68.     Q_PROPERTY( unsigned count READ count )
  69.     
  70. public:
  71.  
  72.     /**
  73.      * Creates a new tabbar.
  74.      */
  75.     KoTabBar( QWidget* parent = 0, const char *name = 0 );
  76.  
  77.     /**
  78.      * Destroy the tabbar.
  79.      */
  80.     virtual ~KoTabBar();
  81.  
  82.     /**
  83.      * Returns true if the tab bar is read only.
  84.      */
  85.     bool readOnly() const;
  86.     
  87.     /**
  88.      * Returns true if tabs and scroll buttons will be laid out in a mirrored 
  89.      * (right to left) fashion.
  90.      */
  91.     bool reverseLayout() const;
  92.     
  93.     /**
  94.      * Returns all the tab as list of strings.
  95.      */
  96.     QStringList tabs() const;
  97.  
  98.     /**
  99.      * Returns number of tabs.
  100.      * This is the same as KoTabBar::tabs().count()
  101.      */
  102.     unsigned count() const;
  103.  
  104.     /**
  105.      * Returns the active tab.
  106.      */
  107.     QString activeTab() const;
  108.  
  109.     /**
  110.      * Returns true if it is possible to scroll one tab back.
  111.      *
  112.      * \sa scrollBack
  113.      */
  114.     bool canScrollBack() const;
  115.  
  116.     /**
  117.      * Returns true if it is possible to scroll one tab forward.
  118.      *
  119.      * \sa scrollForward
  120.      */
  121.     bool canScrollForward() const;
  122.  
  123.     /**
  124.      * Ensures that specified tab is visible.
  125.      */
  126.     void ensureVisible( const QString& tab );
  127.  
  128. public slots:
  129.  
  130.     /**
  131.      * Replaces all tabs with the list of strings.
  132.      */
  133.     void setTabs( const QStringList& list );
  134.  
  135.     /**
  136.      * Sets the tab bar to be read only.
  137.      *
  138.      * If the tab bar is read only, tab reordering is not allowed.
  139.      * This means that signal tabMoved, contextMenu and doubleClicked
  140.      * would not be emitted.
  141.      */
  142.     void setReadOnly( bool ro );
  143.  
  144.     /**
  145.      * If reverse is true, dialogs and scroll buttonswidgets will be laid out in a mirrored
  146.      * as if the sheet is in right to left languages (such as Arabic and Hebrew)
  147.      */
  148.     void setReverseLayout( bool reverse );
  149.  
  150.     /**
  151.      * Adds a tab to the tab bar.
  152.      */
  153.     void addTab( const QString& text );
  154.  
  155.     /**
  156.      * Removes a tab from the bar. If the tab was the active one then
  157.      * no tab will be active.
  158.      * It is recommended to call setActiveTab after a call to this function.
  159.      */
  160.     void removeTab( const QString& text );
  161.  
  162.     /**
  163.      * Renames a tab.
  164.      */
  165.     void renameTab( const QString& old_name, const QString& new_name );
  166.     
  167.     /**
  168.      * Moves a tab to another position and reorder other tabs.
  169.      *
  170.      * Example 1: if there are four tabs A - B - C - D, then
  171.      * moveTab(2,1) will yield A - C - B - D. This is because
  172.      * 2nd tab (i.e C) is moved to a position before 1th tab (i.e B).
  173.      *
  174.      * Example 2: for these tabs: X - Y - Z, moveTab(0,3) will
  175.      * move tab X after tab Z so that the result is Y - Z - X.
  176.      */
  177.     void moveTab( unsigned tab, unsigned target );
  178.  
  179.     /**
  180.      * Scrolls one tab back. Does nothing if the leftmost tab (rightmost tab
  181.      * when reverseLayout is true) is already the first tab.
  182.      *
  183.      * \sa canScrollBack
  184.      */
  185.     void scrollBack();
  186.  
  187.     /**
  188.      * Scrolls one tab forward. Does nothing if the rightmost tab (leftmost tab 
  189.      * when reverseLayout is true) is already the last tab.
  190.      *
  191.      * \sa canScrollForward
  192.      */
  193.     void scrollForward();
  194.  
  195.     /**
  196.      * Scrolls to the first tab. Does nothing if the leftmost tab (rightmost tab
  197.      * when reverseLayout is true) is already the first tab.
  198.      *
  199.      * \sa canScrollBack
  200.      */
  201.     void scrollFirst();
  202.  
  203.     /**
  204.      * Scrolls to the last tab. Does nothing if the rightmost tab (leftmost tab 
  205.      * when reverseLayout is true) is already the last tab.
  206.      *
  207.      * \sa canScrollForward
  208.      */
  209.     void scrollLast();
  210.  
  211.     /**
  212.      * Sets active tab.
  213.      */
  214.     void setActiveTab( const QString& text );
  215.  
  216.     /**
  217.      * Removes all tabs.
  218.      */
  219.     void clear();
  220.     
  221.     QSize sizeHint() const;
  222.  
  223. signals:
  224.  
  225.     /**
  226.      * Emitted if the active tab changed. 
  227.      */
  228.     void tabChanged( const QString& _text );
  229.  
  230.     /**
  231.      * This signal is emitted whenever a tab is dragged, moved and
  232.      * released. This means that the user wants to move a tab into
  233.      * another position (right before target).
  234.      *
  235.      * When the signal is emitted, the tabs are not reordered.
  236.      * Therefore if you just ignore this signal, than no tab reorder
  237.      * is possible. Call moveTab (from the slot connected to this signal)
  238.      * to perform the actual tab reorder.
  239.      */
  240.     void tabMoved( unsigned tab, unsigned target );
  241.  
  242.     /**
  243.      * This signal is emitted whenever the tab bar is right-clicked.
  244.      * Typically it is used to popup a context menu.
  245.      */
  246.     void contextMenu( const QPoint& pos );
  247.  
  248.     /**
  249.      * This signal is emitted whenever the tab bar is double-clicked.
  250.      */
  251.     void doubleClicked();
  252.  
  253. protected slots:
  254.     void autoScrollBack();
  255.     void autoScrollForward();
  256.  
  257. protected:
  258.     virtual void paintEvent ( QPaintEvent* ev );
  259.     virtual void resizeEvent( QResizeEvent* ev );
  260.     virtual void mousePressEvent ( QMouseEvent* ev );
  261.     virtual void mouseReleaseEvent ( QMouseEvent* ev );
  262.     virtual void mouseDoubleClickEvent ( QMouseEvent* ev );
  263.     virtual void mouseMoveEvent ( QMouseEvent* ev );
  264.     virtual void wheelEvent ( QWheelEvent * e );
  265.  
  266. private:
  267.     KoTabBarPrivate *d;
  268.  
  269.     // don't allow copy or assignment
  270.     KoTabBar( const KoTabBar& );
  271.     KoTabBar& operator=( const KoTabBar& );
  272. };
  273.  
  274.  
  275. #endif // kotabbar_h
  276.